#include "detection.h"
#include "BaseDetection.h"
#include "YoloV5Detection.h"

int ObjectDetect::init(const std::string& weight_path)
{
	if (handle){
		delete handle;
		handle = nullptr;
	}
	
	switch (model_type)
	{
	case DET_TYPE::YOLOV5:
		handle = (void *)(new YoloV5Detection(device_id, dataType, use_dynamic, alway_serialize));
		break;
	default:
		handle = nullptr;
		break;
	}
	if (handle != nullptr)
	{
		YoloV5Detection * obj_det = (YoloV5Detection *)handle;
		obj_det->init(weight_path);
	}
}

ObjectDetect::~ObjectDetect()
{	
	if (handle != nullptr)
	{
		YoloV5Detection * obj_det = (YoloV5Detection *)handle;
		obj_det->free();
		handle = nullptr;
	}
}

int ObjectDetect::detect(const std::vector<cv::Mat>& imgs, std::vector<std::vector<Detection>>& dets, int predict_h, int predict_w)
{
    if (handle == nullptr)
        return -1;
	if (handle != nullptr)
	{
		YoloV5Detection * obj_det = (YoloV5Detection *)handle;		
		obj_det->predict(imgs, dets, predict_h, predict_w);
	}
}